<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="author" content="lijinbo" />
    <meta name="cdnload" content="jquery" />
    <title>jqmousemoveEvent</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }
      #moveBar {
        position: absolute;
        width: 200px;
        height: 400px;
        background: #999;
        border: solid 1px #999;
      }
      #banner {
        background: #ddd;
        cursor: move;
      }
    </style>
  </head>
  <body>
    <div id="moveBar">
      <div id="banner">按住鼠标移动当前div</div>
      <div id="content">内容部分</div>
    </div>

    <script>
      dragPanelMove('#banner', '#moveBar')
      function dragPanelMove(downDiv, moveDiv) {
        $(downDiv).mousedown(function (e) {
          var isMove = true
          var div_x = e.pageX - $(moveDiv).offset().left
          var div_y = e.pageY - $(moveDiv).offset().top
          $(document)
            .mousemove(function (e) {
              if (isMove) {
                $(moveDiv).css({ left: e.pageX - div_x, top: e.pageY - div_y })
              }
            })
            .mouseup(function () {
              isMove = false
            })
        })
      }
    </script>
  </body>
</html>
